home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / UNIXTOOL / MEMACS / C / Eval < prev    next >
Text File  |  1990-06-26  |  32KB  |  1,320 lines

  1. /*    EVAL.C: Expresion evaluation functions for
  2.         MicroEMACS
  3.  
  4.     written 1986 by Daniel Lawrence             */
  5.  
  6. #include    <stdio.h>
  7. #include    "estruct.h"
  8. #include    "eproto.h"
  9. #include    "edef.h"
  10. #include    "elang.h"
  11. #include    "evar.h"
  12.  
  13. PASCAL NEAR varinit()    /* initialize the user variable list */
  14.  
  15. {
  16.     register int i;
  17.  
  18.     for (i=0; i < MAXVARS; i++)
  19.         uv[i].u_name[0] = 0;
  20. }
  21.  
  22. PASCAL NEAR varclean()    /* initialize the user variable list */
  23.  
  24. {
  25.     register int i;
  26.  
  27.     for (i=0; i < MAXVARS; i++)
  28.         if (uv[i].u_name[0] != 0)
  29.             free(uv[i].u_value);
  30. }
  31.  
  32. char *PASCAL NEAR gtfun(fname)    /* evaluate a function */
  33.  
  34. char *fname;        /* name of function to evaluate */
  35.  
  36. {
  37.     register int fnum;        /* index to function to eval */
  38.     register int arg;        /* value of some arguments */
  39.     char arg1[NSTRING];        /* value of first argument */
  40.     char arg2[NSTRING];        /* value of second argument */
  41.     char arg3[NSTRING];        /* value of third argument */
  42.     static char result[2 * NSTRING];    /* string result */
  43. #if    ENVFUNC
  44.     char *getenv();         /* get environment string */
  45. #endif
  46.  
  47.     /* look the function up in the function table */
  48.     fname[3] = 0;    /* only first 3 chars significant */
  49.     mklower(fname); /* and let it be upper or lower case */
  50.     fnum = binary(fname, funval, NFUNCS);
  51.  
  52.     /* return errorm on a bad reference */
  53.     if (fnum == -1)
  54.         return(errorm);
  55.  
  56.     /* if needed, retrieve the first argument */
  57.     if (funcs[fnum].f_type >= MONAMIC) {
  58.         if (macarg(arg1) != TRUE)
  59.             return(errorm);
  60.  
  61.         /* if needed, retrieve the second argument */
  62.         if (funcs[fnum].f_type >= DYNAMIC) {
  63.             if (macarg(arg2) != TRUE)
  64.                 return(errorm);
  65.  
  66.             /* if needed, retrieve the third argument */
  67.             if (funcs[fnum].f_type >= TRINAMIC)
  68.                 if (macarg(arg3) != TRUE)
  69.                     return(errorm);
  70.         }
  71.     }
  72.  
  73.  
  74.     /* and now evaluate it! */
  75.     switch (fnum) {
  76.         case UFADD:    return(int_asc(asc_int(arg1) + asc_int(arg2)));
  77.         case UFSUB:    return(int_asc(asc_int(arg1) - asc_int(arg2)));
  78.         case UFTIMES:    return(int_asc(asc_int(arg1) * asc_int(arg2)));
  79.         case UFDIV:    return(int_asc(asc_int(arg1) / asc_int(arg2)));
  80.         case UFMOD:    return(int_asc(asc_int(arg1) % asc_int(arg2)));
  81.         case UFNEG:    return(int_asc(-asc_int(arg1)));
  82.         case UFCAT:    strcpy(result, arg1);
  83.                 return(strcat(result, arg2));
  84.         case UFLEFT:    return(bytecopy(result, arg1, asc_int(arg2)));
  85.         case UFRIGHT:    arg = asc_int(arg2);
  86.                 if (arg > strlen(arg1))
  87.                     arg = strlen(arg1);
  88.                 return(strcpy(result,
  89.                     &arg1[strlen(arg1) - arg]));
  90.         case UFMID:    arg = asc_int(arg2);
  91.                 if (arg > strlen(arg1))
  92.                     arg = strlen(arg1);
  93.                 return(bytecopy(result, &arg1[arg-1],
  94.                     asc_int(arg3)));
  95.         case UFNOT:    return(ltos(stol(arg1) == FALSE));
  96.         case UFEQUAL:    return(ltos(asc_int(arg1) == asc_int(arg2)));
  97.         case UFLESS:    return(ltos(asc_int(arg1) < asc_int(arg2)));
  98.         case UFGREATER: return(ltos(asc_int(arg1) > asc_int(arg2)));
  99.         case UFSEQUAL:    return(ltos(strcmp(arg1, arg2) == 0));
  100.         case UFSLESS:    return(ltos(strcmp(arg1, arg2) < 0));
  101.         case UFSGREAT:    return(ltos(strcmp(arg1, arg2) > 0));
  102.         case UFIND:    return(strcpy(result, fixnull(getval(arg1))));
  103.         case UFAND:    return(ltos(stol(arg1) && stol(arg2)));
  104.         case UFOR:    return(ltos(stol(arg1) || stol(arg2)));
  105.         case UFLENGTH:    return(int_asc(strlen(arg1)));
  106.         case UFUPPER:    return(mkupper(arg1));
  107.         case UFLOWER:    return(mklower(arg1));
  108.         case UFTRUTH:    return(ltos(asc_int(arg1) == 42));
  109.         case UFASCII:    return(int_asc((int)arg1[0]));
  110.         case UFCHR:    result[0] = asc_int(arg1);
  111.                 result[1] = 0;
  112.                 return(result);
  113.         case UFGTCMD:    cmdstr(getcmd(), result);
  114.                 return(result);
  115.         case UFGTKEY:    result[0] = tgetc();
  116.                 result[1] = 0;
  117.                 return(result);
  118.         case UFRND:    return(int_asc((ernd() % absv(asc_int(arg1))) + 1));
  119.         case UFABS:    return(int_asc(absv(asc_int(arg1))));
  120.         case UFSINDEX:    return(int_asc(sindex(arg1, arg2)));
  121.         case UFENV:
  122. #if    ENVFUNC
  123.                 return(fixnull(getenv(arg1)));
  124. #else
  125.                 return("");
  126. #endif
  127.         case UFBIND:    return(transbind(arg1));
  128.         case UFEXIST:    return(ltos(fexist(arg1)));
  129.         case UFFIND:
  130.                 return(fixnull(flook(arg1, TRUE)));
  131.         case UFBAND:    return(int_asc(asc_int(arg1) & asc_int(arg2)));
  132.         case UFBOR:    return(int_asc(asc_int(arg1) | asc_int(arg2)));
  133.         case UFBXOR:    return(int_asc(asc_int(arg1) ^ asc_int(arg2)));
  134.         case UFBNOT:    return(int_asc(~asc_int(arg1)));
  135.         case UFXLATE:    return(xlat(arg1, arg2, arg3));
  136.         case UFTRIM:    return(trimstr(arg1));
  137.         case UFSLOWER:    return(setlower(arg1, arg2), "");
  138.         case UFSUPPER:    return(setupper(arg1, arg2), "");
  139.          case UFISNUM:    return(ltos(is_num(arg1)));
  140.     }
  141.  
  142.     meexit(-11);    /* never should get here */
  143. }
  144.  
  145. char *PASCAL NEAR gtusr(vname)    /* look up a user var's value */
  146.  
  147. char *vname;        /* name of user variable to fetch */
  148.  
  149. {
  150.     register int vnum;    /* ordinal number of user var */
  151.     register char *vptr;    /* temp pointer to function value */
  152.  
  153.     /* limit comparisons to significant length */
  154.     if (strlen(vname) >= NVSIZE)    /* "%" counts, but is not passed */
  155.         vname[NVSIZE-1] = '\0';
  156.  
  157.     /* scan the list looking for the user var name */
  158.     for (vnum = 0; vnum < MAXVARS; vnum++) {
  159.         if (uv[vnum].u_name[0] == 0)
  160.             return(errorm);
  161.         if (strcmp(vname, uv[vnum].u_name) == 0) {
  162.             vptr = uv[vnum].u_value;
  163.             if (vptr)
  164.                 return(vptr);
  165.             else
  166.                 return(errorm);
  167.         }
  168.     }
  169.  
  170.     /* return errorm if we run off the end */
  171.     return(errorm);
  172. }
  173.  
  174. char *PASCAL NEAR funval(i)
  175.  
  176. int i;
  177.  
  178. {
  179.     return(funcs[i].f_name);
  180. }
  181.  
  182. char *PASCAL NEAR envval(i)
  183.  
  184. int i;
  185.  
  186. {
  187.     return(envars[i]);
  188. }
  189.  
  190. PASCAL NEAR binary(key, tval, tlength)
  191.  
  192. char *key;        /* key string to look for */
  193. char *(PASCAL NEAR *tval)();    /* ptr to function to fetch table value with */
  194. int tlength;        /* length of table to search */
  195.  
  196. {
  197.     int l, u;    /* lower and upper limits of binary search */
  198.     int i;        /* current search index */
  199.     int cresult;    /* result of comparison */
  200.  
  201.     /* set current search limit as entire list */
  202.     l = 0;
  203.     u = tlength - 1;
  204.  
  205.     /* get the midpoint! */
  206.     while (u >= l) {
  207.         i = (l + u) >> 1;
  208.  
  209.         /* do the comparison */
  210.         cresult = strcmp(key, (*tval)(i));
  211.         if (cresult == 0)
  212.             return(i);
  213.         if (cresult < 0)
  214.             u = i - 1;
  215.         else
  216.             l = i + 1;
  217.     }
  218.     return(-1);
  219. }
  220.  
  221. char *PASCAL NEAR gtenv(vname)
  222.  
  223. char *vname;        /* name of environment variable to retrieve */
  224.  
  225. {
  226.     register int vnum;    /* ordinal number of var refrenced */
  227.     static char result[2 * NSTRING];    /* string result */
  228.  
  229.     /* scan the list, looking for the referenced name */
  230.     vnum = binary(vname, envval, NEVARS);
  231.  
  232.     /* return errorm on a bad reference */
  233.     if (vnum == -1)
  234.         return(errorm);
  235.  
  236.     /* otherwise, fetch the appropriate value */
  237.     switch (vnum) {
  238.         case EVFILLCOL: return(int_asc(fillcol));
  239.         case EVPAGELEN: return(int_asc(term.t_nrow + 1));
  240.         case EVCURCOL:    return(int_asc(getccol(FALSE)));
  241.         case EVCURLINE: return(int_asc(getlinenum(curbp, curwp->w_dotp)));
  242.         case EVRAM:    return(int_asc((int)(envram / 1024l)));
  243.         case EVFLICKER: return(ltos(flickcode));
  244.         case EVCURWIDTH:return(int_asc(term.t_ncol));
  245.         case EVCBFLAGS: return(int_asc(curbp->b_flag));
  246.         case EVCBUFNAME:return(curbp->b_bname);
  247.         case EVCFNAME:    return(curbp->b_fname);
  248.         case EVSRES:    return(sres);
  249.         case EVDEBUG:    return(ltos(macbug));
  250.         case EVSTATUS:    return(ltos(cmdstatus));
  251.         case EVPALETTE: return(palstr);
  252.         case EVASAVE:    return(int_asc(gasave));
  253.         case EVACOUNT:    return(int_asc(gacount));
  254.         case EVLASTKEY: return(int_asc(lastkey));
  255.         case EVCURCHAR:
  256.             return(curwp->w_dotp->l_used ==
  257.                     curwp->w_doto ? int_asc('\r') :
  258.                 int_asc(lgetc(curwp->w_dotp, curwp->w_doto)));
  259.         case EVDISCMD:    return(ltos(discmd));
  260.         case EVVERSION: return(VERSION);
  261.         case EVPROGNAME:return(PROGNAME);
  262.         case EVLANG:    return(LANGUAGE);
  263.         case EVSEED:    return(int_asc(seed));
  264.         case EVDISINP:    return(ltos(disinp));
  265.         case EVWLINE:    return(int_asc(curwp->w_ntrows));
  266.         case EVCWLINE:    return(int_asc(getwpos()));
  267.         case EVTARGET:    saveflag = lastflag;
  268.                 return(int_asc(curgoal));
  269.         case EVSEARCH:    return(pat);
  270.         case EVTIME:    return(timeset());
  271.         case EVREPLACE: return(rpat);
  272.         case EVMATCH:    return(fixnull(patmatch));
  273.         case EVKILL:    return(getkill());
  274.         case EVREGION:    return(getreg());
  275.         case EVCMODE:    return(int_asc(curbp->b_mode));
  276.         case EVGMODE:    return(int_asc(gmode));
  277.         case EVTPAUSE:    return(int_asc(term.t_pause));
  278.         case EVPENDING:
  279. #if    TYPEAH
  280.                 return(ltos(typahead()));
  281. #else
  282.                 return(falsem);
  283. #endif
  284.         case EVLWIDTH:    return(int_asc(llength(curwp->w_dotp)));
  285.         case EVLINE:    return(getctext());
  286.         case EVGFLAGS:    return(int_asc(gflags));
  287.         case EVRVAL:    return(int_asc(rval));
  288.         case EVREADHK:    return(fixnull(getfname(&readhook)));
  289.         case EVWRAPHK:    return(fixnull(getfname(&wraphook)));
  290.         case EVCMDHK:    return(fixnull(getfname(&cmdhook)));
  291.         case EVXPOS:    return(int_asc(xpos));
  292.         case EVYPOS:    return(int_asc(ypos));
  293.         case EVSTERM:    cmdstr(sterm, result);
  294.                 return(result);
  295.         case EVMODEFLAG:return(ltos(modeflag));
  296.         case EVSSCROLL: return(ltos(sscroll));
  297.         case EVLASTMESG:return(lastmesg);
  298.         case EVHARDTAB: return(int_asc(tabsize));
  299.         case EVSOFTTAB: return(int_asc(stabsize));
  300.         case EVSSAVE:    return(ltos(ssave));
  301.         case EVFCOL:    return(int_asc(curwp->w_fcol));
  302.         case EVHSCROLL: return(ltos(hscroll));
  303.         case EVHJUMP:    return(int_asc(hjump));
  304.         case EVBUFHOOK: return(fixnull(getfname(&bufhook)));
  305.         case EVEXBHOOK: return(fixnull(getfname(&exbhook)));
  306.         case EVWRITEHK: return(fixnull(getfname(&writehook)));
  307.         case EVDIAGFLAG:return(ltos(diagflag));
  308.         case EVMSFLAG:    return(ltos(mouseflag));
  309.         case EVOCRYPT:    return(ltos(oldcrypt));
  310.         case EVSEARCHPNT:    return(int_asc(searchtype));
  311.         case EVDISPHIGH:return(ltos(disphigh));
  312.         case EVCFTYPE:
  313. #if    FTYPE
  314.                 return(int_asc(curbp->b_type));
  315. #else
  316.                 return(falsem);
  317. #endif
  318.         case EVLTERM:    return(lterm);
  319.         case EVWCHARS:    return(getwlist(result));
  320.         case EVPOPFLAG: return(ltos(popflag));
  321.         case EVYANKPNT:    return(ltos(yanktype));
  322.         case EVSCRNAME:    return(cur_screen->s_screen_name);
  323.         case EVSCRNUM:    return(int_asc(scr_num));
  324.         case EVCURWIND: return(int_asc(getcwnum()));
  325.         case EVNUMWIND: return(int_asc(gettwnum()));
  326.     }
  327.     meexit(-12);    /* again, we should never get here */
  328. }
  329.  
  330. char *PASCAL NEAR fixnull(s)    /* Don't return NULL pointers! */
  331.  
  332. char *s;
  333.  
  334. {
  335.     if (s == NULL)
  336.         return("");
  337.     else
  338.         return(s);
  339. }
  340.  
  341. /* return some of the contents of the kill buffer */
  342.  
  343. char *PASCAL NEAR getkill()
  344.  
  345. {
  346.     register int size;    /* max number of chars to return */
  347.     static char value[NSTRING];    /* temp buffer for value */
  348.  
  349.     if (kbufh == NULL)
  350.         /* no kill buffer....just a null string */
  351.         value[0] = 0;
  352.     else {
  353.         /* copy in the contents... */
  354.         if (kused < NSTRING)
  355.             size = kused;
  356.         else
  357.             size = NSTRING - 1;
  358.         bytecopy(value, kbufh->d_chunk, size);
  359.         value[NSTRING - 1] = 0;
  360.     }
  361.  
  362.     /* and return the constructed value */
  363.     return(value);
  364. }
  365.  
  366. char *PASCAL NEAR trimstr(s)    /* trim whitespace off the end of a string */
  367.  
  368. char *s;    /* string to trim */
  369.  
  370. {
  371.     char *sp;    /* backward index */
  372.  
  373.     sp = s + strlen(s) - 1;
  374.     while ((sp >= s) && (*sp == ' ' || *sp == '\t'))
  375.         --sp;
  376.     *(sp+1) = 0;
  377.     return(s);
  378. }
  379.  
  380. int PASCAL NEAR setvar(f, n)        /* set a variable */
  381.  
  382. int f;        /* default flag */
  383. int n;        /* numeric arg (can overide prompted value) */
  384.  
  385. {
  386.     register int status;    /* status return */
  387.     VDESC vd;        /* variable num/type */
  388.     char var[NVSIZE+1];    /* name of variable to fetch */
  389.     char value[NSTRING];    /* value to set variable to */
  390.  
  391.     /* first get the variable to set.. */
  392.     if (clexec == FALSE) {
  393.         status = mlreply(TEXT51, &var[0], NVSIZE+1);
  394. /*                 "Variable to set: " */
  395.         if (status != TRUE)
  396.             return(status);
  397.     } else {    /* macro line argument */
  398.         /* grab token and skip it */
  399.         execstr = token(execstr, var, NVSIZE + 1);
  400.     }
  401.  
  402.     /* check the legality and find the var */
  403.     findvar(var, &vd, NVSIZE + 1);
  404.         
  405.     /* if its not legal....bitch */
  406.     if (vd.v_type == -1) {
  407.         mlwrite(TEXT52, var);
  408. /*            "%%No such variable as '%s'" */
  409.         return(FALSE);
  410.     }
  411.  
  412.     /* get the value for that variable */
  413.     if (f == TRUE)
  414.         strcpy(value, int_asc(n));
  415.     else {
  416.         status = mlreply(TEXT53, &value[0], NSTRING);
  417. /*                 "Value: " */
  418.         if (status != TRUE)
  419.             return(status);
  420.     }
  421.  
  422.     /* and set the appropriate value */
  423.     status = svar(&vd, value);
  424.  
  425. #if    DEBUGM
  426.     /* if $debug == TRUE, every assignment will echo a statment to
  427.        that effect here. */
  428.         
  429.     if (macbug && (strcmp(var, "%track") != 0)) {
  430.         strcpy(outline, "(((");
  431.  
  432.         strcat(outline, var);
  433.         strcat(outline, " <- ");
  434.  
  435.         /* and lastly the value we tried to assign */
  436.         strcat(outline, value);
  437.         strcat(outline, ")))");
  438.  
  439.         /* expand '%' to "%%" so mlwrite wont bitch */
  440.         makelit(outline);
  441.  
  442.         /* write out the debug line */
  443.         mlforce(outline);
  444.         update(TRUE);
  445.  
  446.         /* and get the keystroke to hold the output */
  447.         if (getkey() == abortc) {
  448.             mlforce(TEXT54);
  449. /*                "[Macro aborted]" */
  450.             status = FALSE;
  451.         }
  452.     }
  453. #endif
  454.  
  455.     /* and return it */
  456.     return(status);
  457. }
  458.  
  459. PASCAL NEAR findvar(var, vd, size)    /* find a variables type and name */
  460.  
  461. char *var;    /* name of var to get */
  462. VDESC *vd;    /* structure to hold type and ptr */
  463. int size;    /* size of var array */
  464.  
  465. {
  466.     register int vnum;    /* subscript in varable arrays */
  467.     register int vtype;    /* type to return */
  468.  
  469. fvar:    vtype = -1;
  470.     switch (var[0]) {
  471.  
  472.         case '$': /* check for legal enviromnent var */
  473.             for (vnum = 0; vnum < NEVARS; vnum++)
  474.                 if (strcmp(&var[1], envars[vnum]) == 0) {
  475.                     vtype = TKENV;
  476.                     break;
  477.                 }
  478.             break;
  479.  
  480.         case '%': /* check for existing legal user variable */
  481.             for (vnum = 0; vnum < MAXVARS; vnum++)
  482.                 if (strcmp(&var[1], uv[vnum].u_name) == 0) {
  483.                     vtype = TKVAR;
  484.                     break;
  485.                 }
  486.             if (vnum < MAXVARS)
  487.                 break;
  488.  
  489.             /* create a new one??? */
  490.             for (vnum = 0; vnum < MAXVARS; vnum++)
  491.                 if (uv[vnum].u_name[0] == 0) {
  492.                     vtype = TKVAR;
  493.                     strcpy(uv[vnum].u_name, &var[1]);
  494.                     uv[vnum].u_value = NULL;
  495.                     break;
  496.                 }
  497.             break;
  498.  
  499.         case '&':    /* indirect operator? */
  500.             var[4] = 0;
  501.             if (strcmp(&var[1], "ind") == 0) {
  502.                 /* grab token, and eval it */
  503.                 execstr = token(execstr, var, size);
  504.                 strcpy(var, fixnull(getval(var)));
  505.                 goto fvar;
  506.             }
  507.     }
  508.  
  509.     /* return the results */
  510.     vd->v_num = vnum;
  511.     vd->v_type = vtype;
  512.     return;
  513. }
  514.  
  515. int PASCAL NEAR svar(var, value)    /* set a variable */
  516.  
  517. VDESC *var;    /* variable to set */
  518. char *value;    /* value to set to */
  519.  
  520. {
  521.     register int vnum;    /* ordinal number of var refrenced */
  522.     register int vtype;    /* type of variable to set */
  523.     register int status;    /* status return */
  524.     register int c;     /* translated character */
  525.     register char *sp;    /* scratch string pointer */
  526.  
  527.     /* simplify the vd structure (we are gonna look at it a lot) */
  528.     vnum = var->v_num;
  529.     vtype = var->v_type;
  530.  
  531.     /* and set the appropriate value */
  532.     status = TRUE;
  533.     switch (vtype) {
  534.     case TKVAR: /* set a user variable */
  535.         if (uv[vnum].u_value != NULL)
  536.             free(uv[vnum].u_value);
  537.         sp = malloc(strlen(value) + 1);
  538.         if (sp == NULL)
  539.             return(FALSE);
  540.         strcpy(sp, value);
  541.         uv[vnum].u_value = sp;
  542.         break;
  543.  
  544.     case TKENV: /* set an environment variable */
  545.         status = TRUE;    /* by default */
  546.         switch (vnum) {
  547.         case EVFILLCOL: fillcol = asc_int(value);
  548.                 break;
  549.         case EVPAGELEN: status = newsize(TRUE, asc_int(value));
  550.                 break;
  551.         case EVCURCOL:    status = setccol(asc_int(value));
  552.                 break;
  553.         case EVCURLINE: status = gotoline(TRUE, asc_int(value));
  554.                 break;
  555.         case EVRAM:    break;
  556.         case EVFLICKER: flickcode = stol(value);
  557.                 break;
  558.         case EVCURWIDTH:status = newwidth(TRUE, asc_int(value));
  559.                 break;
  560.         case EVCBFLAGS: curbp->b_flag = (curbp->b_flag & ~(BFCHG|BFINVS))
  561.                     | (asc_int(value) & (BFCHG&BFINVS));
  562.                 lchange(WFMODE);
  563.                 break;
  564.         case EVCBUFNAME:strcpy(curbp->b_bname, value);
  565.                 curwp->w_flag |= WFMODE;
  566.                 break;
  567.         case EVCFNAME:    strcpy(curbp->b_fname, value);
  568.                 curwp->w_flag |= WFMODE;
  569.                 break;
  570.         case EVSRES:    status = TTrez(value);
  571.                 break;
  572.         case EVDEBUG:    macbug = stol(value);
  573.                 break;
  574.         case EVSTATUS:    cmdstatus = stol(value);
  575.                 break;
  576.         case EVPALETTE: bytecopy(palstr, value, 48);
  577.                 spal(palstr);
  578.                 break;
  579.         case EVASAVE:    gasave = asc_int(value);
  580.                 break;
  581.         case EVACOUNT:    gacount = asc_int(value);
  582.                 break;
  583.         case EVLASTKEY: lastkey = asc_int(value);
  584.                 break;
  585.         case EVCURCHAR: ldelete(1L, FALSE);    /* delete 1 char */
  586.                 c = asc_int(value);
  587.                 if (c == '\r')
  588.                     lnewline();
  589.                 else
  590.                     linsert(1, c);
  591.                 backchar(FALSE, 1);
  592.                 break;
  593.         case EVDISCMD:    discmd = stol(value);
  594.                 break;
  595.         case EVVERSION: break;
  596.         case EVPROGNAME:break;
  597.         case EVLANG:    break;
  598.         case EVSEED:    seed = asc_int(value);
  599.                 break;
  600.         case EVDISINP:    disinp = stol(value);
  601.                 break;
  602.         case EVWLINE:    status = resize(TRUE, asc_int(value));
  603.                 break;
  604.         case EVCWLINE:    status = forwline(TRUE,
  605.                         asc_int(value) - getwpos());
  606.                 break;
  607.         case EVTARGET:    curgoal = asc_int(value);
  608.                 thisflag = saveflag;
  609.                 break;
  610.         case EVSEARCH:    strcpy(pat, value);
  611.                 setjtable(); /* Set up fast search arrays  */
  612. #if    MAGIC
  613.                 mcclear();
  614. #endif
  615.                 break;
  616.         case EVTIME:    break;
  617.         case EVREPLACE: strcpy(rpat, value);
  618. #if    MAGIC
  619.                 rmcclear();
  620. #endif 
  621.                 break;
  622.         case EVMATCH:    break;
  623.         case EVKILL:    break;
  624.         case EVREGION:    break;
  625.         case EVCMODE:    curbp->b_mode = asc_int(value);
  626.                 curwp->w_flag |= WFMODE;
  627.                 break;
  628.         case EVGMODE:    gmode = asc_int(value);
  629.                 break;
  630.         case EVTPAUSE:    term.t_pause = asc_int(value);
  631.                 break;
  632.         case EVPENDING: break;
  633.         case EVLWIDTH:    break;
  634.         case EVLINE:    putctext(value);
  635.                 break;
  636.         case EVGFLAGS:    gflags = asc_int(value);
  637.                 break;
  638.         case EVRVAL:    break;
  639.         case EVREADHK:    setkey(&readhook, BINDFNC, value);
  640.                 break;
  641.         case EVWRAPHK:    setkey(&wraphook, BINDFNC, value);
  642.                 break;
  643.         case EVCMDHK:    setkey(&cmdhook, BINDFNC, value);
  644.                 break;
  645.         case EVXPOS:    xpos = asc_int(value);
  646.                 break;
  647.         case EVYPOS:    ypos = asc_int(value);
  648.                 break;
  649.         case EVSTERM:    sterm = stock(value);
  650.                 break;
  651.         case EVMODEFLAG:modeflag = stol(value);
  652.                 upwind();
  653.                 break;
  654.         case EVSSCROLL: sscroll = stol(value);
  655.                 break;
  656.         case EVLASTMESG:strcpy(lastmesg, value);
  657.                 break;
  658.         case EVHARDTAB: tabsize = asc_int(value);
  659.                 upwind();
  660.                 break;
  661.         case EVSOFTTAB: stabsize = asc_int(value);
  662.                 upwind();
  663.                 break;
  664.         case EVSSAVE:    ssave = stol(value);
  665.                 break;
  666.         case EVFCOL:    curwp->w_fcol = asc_int(value);
  667.                 if (curwp->w_fcol < 0)
  668.                     curwp->w_fcol = 0;
  669.                 curwp->w_flag |= WFHARD | WFMODE;
  670.                 break;
  671.         case EVHSCROLL: hscroll = stol(value);
  672.                 lbound = 0;
  673.                 break;
  674.         case EVHJUMP:    hjump = asc_int(value);
  675.                 if (hjump < 1)
  676.                     hjump = 1;
  677.                 if (hjump > term.t_ncol - 1)
  678.                     hjump = term.t_ncol - 1;
  679.                 break;
  680.         case EVBUFHOOK: setkey(&bufhook, BINDFNC, value);
  681.                 break;
  682.         case EVEXBHOOK: setkey(&exbhook, BINDFNC, value);
  683.                 break;
  684.         case EVWRITEHK: setkey(&writehook, BINDFNC, value);
  685.                 break;
  686.         case EVDIAGFLAG:diagflag = stol(value);
  687.                 break;
  688.         case EVMSFLAG:    mouseflag = stol(value);
  689.                 break;
  690.         case EVOCRYPT:    oldcrypt = stol(value);
  691.                 break;
  692.         case EVSEARCHPNT:    searchtype = asc_int(value);
  693.                 if (searchtype < SRNORM  || searchtype > SREND)
  694.                     searchtype = SRNORM;
  695.                 break;
  696.         case EVDISPHIGH:
  697.                 c = disphigh;
  698.                 disphigh = stol(value);
  699.                 if (c != disphigh)
  700.                     upwind();
  701.  
  702.                 break;
  703.         case EVCFTYPE:
  704. #if    FTYPE
  705.                 curbp->b_type = maketype(value);
  706. #endif
  707.                 break;
  708.         case EVLTERM:    bytecopy(lterm, value, NSTRING);
  709.                 break;
  710.         case EVWCHARS:    setwlist(value);
  711.                 break;
  712.         case EVPOPFLAG: popflag = stol(value);
  713.                 break;
  714.         case EVYANKPNT:    yanktype = stol(value);
  715.                 break;
  716.         case EVSCRNAME:    select_screen(lookup_screen(value));
  717.                 break;
  718.         case EVSCRNUM:    select_screen(index_screen(asc_int(value)));
  719.                 break;
  720.         case EVCURWIND:    nextwind(TRUE, asc_int(value));
  721.                 break;
  722.         case EVNUMWIND:    break;
  723.         }
  724.         break;
  725.     }
  726.     return(status);
  727. }
  728.  
  729. /*    asc_int:    ascii string to integer......This is too
  730.         inconsistant to use the system's    */
  731.  
  732. int PASCAL NEAR asc_int(st)
  733.  
  734. char *st;
  735.  
  736. {
  737.     int result;    /* resulting number */
  738.     int sign;    /* sign of resulting number */
  739.     char c;     /* current char being examined */
  740.  
  741.     result = 0;
  742.     sign = 1;
  743.  
  744.     /* skip preceding whitespace */
  745.     while (*st == ' ' || *st == '\t')
  746.         ++st;
  747.  
  748.     /* check for sign */
  749.     if (*st == '-') {
  750.         sign = -1;
  751.         ++st;
  752.     }
  753.     if (*st == '+')
  754.         ++st;
  755.  
  756.     /* scan digits, build value */
  757.     while ((c = *st++))
  758.         if (c >= '0' && c <= '9')
  759.             result = result * 10 + c - '0';
  760.         else
  761.             break;
  762.  
  763.     return(result * sign);
  764. }
  765.  
  766. /*    int_asc:    integer to ascii string.......... This is too
  767.             inconsistant to use the system's    */
  768.  
  769. char *PASCAL NEAR int_asc(i)
  770.  
  771. int i;    /* integer to translate to a string */
  772.  
  773. {
  774.     register int digit;        /* current digit being used */
  775.     register char *sp;        /* pointer into result */
  776.     register int sign;        /* sign of resulting number */
  777.     static char result[INTWIDTH+1]; /* resulting string */
  778.  
  779.     /* record the sign...*/
  780.     sign = 1;
  781.     if (i < 0) {
  782.         sign = -1;
  783.         i = -i;
  784.     }
  785.  
  786.     /* and build the string (backwards!) */
  787.     sp = result + INTWIDTH;
  788.     *sp = 0;
  789.     do {
  790.         digit = i % 10;
  791.         *(--sp) = '0' + digit;    /* and install the new digit */
  792.         i = i / 10;
  793.     } while (i);
  794.  
  795.     /* and fix the sign */
  796.     if (sign == -1) {
  797.         *(--sp) = '-';    /* and install the minus sign */
  798.     }
  799.  
  800.     return(sp);
  801. }
  802.  
  803. int PASCAL NEAR gettyp(token)    /* find the type of a passed token */
  804.  
  805. char *token;    /* token to analyze */
  806.  
  807. {
  808.     register char c;    /* first char in token */
  809.  
  810.     /* grab the first char (this is all we need) */
  811.     c = *token;
  812.  
  813.     /* no blanks!!! */
  814.     if (c == 0)
  815.         return(TKNUL);
  816.  
  817.     /* a numeric literal? */
  818.     if (c >= '0' && c <= '9')
  819.         return(TKLIT);
  820.  
  821.     switch (c) {
  822.         case '"':    return(TKSTR);
  823.  
  824.         case '!':    return(TKDIR);
  825.         case '@':    return(TKARG);
  826.         case '#':    return(TKBUF);
  827.         case '$':    return(TKENV);
  828.         case '%':    return(TKVAR);
  829.         case '&':    return(TKFUN);
  830.         case '*':    return(TKLBL);
  831.  
  832.         default:    return(TKCMD);
  833.     }
  834. }
  835.  
  836. char *PASCAL NEAR getval(token) /* find the value of a token */
  837.  
  838. char *token;        /* token to evaluate */
  839.  
  840. {
  841.     register int status;    /* error return */
  842.     register BUFFER *bp;    /* temp buffer pointer */
  843.     register int blen;    /* length of buffer argument */
  844.     register int distmp;    /* temporary discmd flag */
  845.     static char buf[NSTRING];/* string buffer for some returns */
  846.  
  847.     switch (gettyp(token)) {
  848.         case TKNUL:    return("");
  849.  
  850.         case TKARG:    /* interactive argument */
  851.                 strcpy(token, fixnull(getval(&token[1])));
  852.                 distmp = discmd;    /* echo it always! */
  853.                 discmd = TRUE;
  854.                 status = getstring(token,
  855.                        buf, NSTRING, ctoec('\r'));
  856.                 discmd = distmp;
  857.                 if (status == ABORT)
  858.                     return(NULL);
  859.                 return(buf);
  860.  
  861.         case TKBUF:    /* buffer contents fetch */
  862.  
  863.                 /* grab the right buffer */
  864.                 strcpy(token, fixnull(getval(&token[1])));
  865.                 bp = bfind(token, FALSE, 0);
  866.                 if (bp == NULL)
  867.                     return(NULL);
  868.             
  869.                 /* if the buffer is displayed, get the window
  870.                    vars instead of the buffer vars */
  871.                 if (bp->b_nwnd > 0) {
  872.                     curbp->b_dotp = curwp->w_dotp;
  873.                     curbp->b_doto = curwp->w_doto;
  874.                 }
  875.  
  876.                 /* make sure we are not at the end */
  877.                 if (bp->b_linep == bp->b_dotp)
  878.                     return(NULL);
  879.             
  880.                 /* grab the line as an argument */
  881.                 blen = bp->b_dotp->l_used - bp->b_doto;
  882.                 if (blen > NSTRING)
  883.                     blen = NSTRING;
  884.                 bytecopy(buf, bp->b_dotp->l_text + bp->b_doto,
  885.                     blen);
  886.                 buf[blen] = 0;
  887.             
  888.                 /* and step the buffer's line ptr ahead a line */
  889.                 bp->b_dotp = bp->b_dotp->l_fp;
  890.                 bp->b_doto = 0;
  891.  
  892.                 /* if displayed buffer, reset window ptr vars*/
  893.                 if (bp->b_nwnd > 0) {
  894.                     curwp->w_dotp = curbp->b_dotp;
  895.                     curwp->w_doto = 0;
  896.                     curwp->w_flag |= WFMOVE;
  897.                 }
  898.  
  899.                 /* and return the spoils */
  900.                 return(buf);            
  901.  
  902.         case TKVAR:    return(gtusr(token+1));
  903.         case TKENV:    return(gtenv(token+1));
  904.         case TKFUN:    return(gtfun(token+1));
  905.         case TKDIR:    return(NULL);
  906.         case TKLBL:    return(NULL);
  907.         case TKLIT:    return(token);
  908.         case TKSTR:    return(token+1);
  909.         case TKCMD:    return(token);
  910.     }
  911. }
  912.  
  913. int PASCAL NEAR stol(val)    /* convert a string to a numeric logical */
  914.  
  915. char *val;    /* value to check for stol */
  916.  
  917. {
  918.     /* check for logical values */
  919.     if (val[0] == 'F')
  920.         return(FALSE);
  921.     if (val[0] == 'T')
  922.         return(TRUE);
  923.  
  924.     /* check for numeric truth (!= 0) */
  925.     return((asc_int(val) != 0));
  926. }
  927.  
  928. char *PASCAL NEAR ltos(val)    /* numeric logical to string logical */
  929.  
  930. int val;    /* value to translate */
  931.  
  932. {
  933.     if (val)
  934.         return(truem);
  935.     else
  936.         return(falsem);
  937. }
  938.  
  939. char *PASCAL NEAR mkupper(str)    /* make a string upper case */
  940.  
  941. char *str;        /* string to upper case */
  942.  
  943. {
  944.     char *sp;
  945.  
  946.     sp = str;
  947.     while (*sp)
  948.         uppercase(sp++);
  949.     return(str);
  950. }
  951.  
  952. char *PASCAL NEAR mklower(str)    /* make a string lower case */
  953.  
  954. char *str;        /* string to lower case */
  955.  
  956. {
  957.     char *sp;
  958.  
  959.     sp = str;
  960.     while (*sp)
  961.         lowercase(sp++);
  962.     return(str);
  963. }
  964.  
  965. int PASCAL NEAR absv(x) /* take the absolute value of an integer */
  966.  
  967. int x;
  968.  
  969. {
  970.     return(x < 0 ? -x : x);
  971. }
  972.  
  973. int PASCAL NEAR ernd()    /* returns a random integer */
  974.  
  975. {
  976.     seed = absv(seed * 1721 + 10007);
  977.     return(seed);
  978. }
  979.  
  980. int PASCAL NEAR sindex(source, pattern) /* find pattern within source */
  981.  
  982. char *source;    /* source string to search */
  983. char *pattern;    /* string to look for */
  984.  
  985. {
  986.     char *sp;    /* ptr to current position to scan */
  987.     char *csp;    /* ptr to source string during comparison */
  988.     char *cp;    /* ptr to place to check for equality */
  989.  
  990.     /* scanning through the source string */
  991.     sp = source;
  992.     while (*sp) {
  993.         /* scan through the pattern */
  994.         cp = pattern;
  995.         csp = sp;
  996.         while (*cp) {
  997.             if (!eq(*cp, *csp))
  998.                 break;
  999.             ++cp;
  1000.             ++csp;
  1001.         }
  1002.  
  1003.         /* was it a match? */
  1004.         if (*cp == 0)
  1005.             return((int)(sp - source) + 1);
  1006.         ++sp;
  1007.     }
  1008.  
  1009.     /* no match at all.. */
  1010.     return(0);
  1011. }
  1012.  
  1013. /*    Filter a string through a translation table    */
  1014.  
  1015. char *PASCAL NEAR xlat(source, lookup, trans)
  1016.  
  1017. char *source;    /* string to filter */
  1018. char *lookup;    /* characters to translate */
  1019. char *trans;    /* resulting translated characters */
  1020.  
  1021. {
  1022.     register char *sp;    /* pointer into source table */
  1023.     register char *lp;    /* pointer into lookup table */
  1024.     register char *rp;    /* pointer into result */
  1025.     static char result[NSTRING];    /* temporary result */
  1026.  
  1027.     /* scan source string */
  1028.     sp = source;
  1029.     rp = result;
  1030.     while (*sp) {
  1031.         /* scan lookup table for a match */
  1032.         lp = lookup;
  1033.         while (*lp) {
  1034.             if (*sp == *lp) {
  1035.                 *rp++ = trans[lp - lookup];
  1036.                 goto xnext;
  1037.             }
  1038.             ++lp;
  1039.         }
  1040.  
  1041.         /* no match, copy in the source char untranslated */
  1042.         *rp++ = *sp;
  1043.  
  1044. xnext:        ++sp;
  1045.     }
  1046.  
  1047.     /* terminate and return the result */
  1048.     *rp = 0;
  1049.     return(result);
  1050. }
  1051.  
  1052. /*    setwlist:    Set an alternative list of character to be
  1053.             considered "in a word */
  1054.  
  1055. PASCAL NEAR setwlist(wclist)
  1056.  
  1057. char *wclist;    /* list of characters to consider "in a word" */
  1058.  
  1059. {
  1060.     register int index;
  1061.  
  1062.     /* if we are turning this facility off, just flag so */
  1063.     if (wclist == NULL || *wclist == 0) {
  1064.         wlflag = FALSE;
  1065.         return;
  1066.     }
  1067.  
  1068.     /* first clear the table */
  1069.     for (index = 0; index < 256; index++)
  1070.         wordlist[index] = FALSE;
  1071.  
  1072.     /* and for each character in the new value, set that element
  1073.        of the word character list */
  1074.     while (*wclist)
  1075.         wordlist[*wclist++] = TRUE;
  1076.     wlflag = TRUE;
  1077.     return;
  1078. }
  1079.  
  1080. /*    getwlist:    place in a buffer a list of characters
  1081.             considered "in a word"            */
  1082.  
  1083. char *PASCAL NEAR getwlist(buf)
  1084.  
  1085. char *buf;    /* buffer to place list of characters */
  1086.  
  1087. {
  1088.     register int index;
  1089.     register char *sp;
  1090.  
  1091.     /* if we are defaulting to a standard word char list... */
  1092.     if (wlflag == FALSE)
  1093.         return("");
  1094.  
  1095.     /* build the string of characters in the return buffer */
  1096.     sp = buf;
  1097.     for (index = 0; index < 256; index++)
  1098.         if (wordlist[index])
  1099.             *sp++ = index;
  1100.     *sp = 0;
  1101.     return(buf);
  1102. }
  1103.  
  1104. /*    is_num:    ascii string is integer......This is too
  1105.         inconsistant to use the system's    */
  1106.  
  1107. int PASCAL NEAR is_num(st)
  1108.  
  1109. char *st;
  1110.  
  1111. {
  1112.     int period_flag;    /* have we seen a period yet? */
  1113.  
  1114.     /* skip preceding whitespace */
  1115.     while (*st == ' ' || *st == '\t')
  1116.         ++st;
  1117.  
  1118.     /* check for sign */
  1119.     if ((*st == '-') || (*st == '+'))
  1120.         ++st;
  1121.  
  1122.     /* scan digits */
  1123.     period_flag = FALSE;
  1124.     while ((*st >= '0') && (*st <= '9') ||
  1125.            (*st == '.' && period_flag == FALSE)) {
  1126.         if (*st == '.')
  1127.             period_flag = TRUE;
  1128.         st++;
  1129.     }
  1130.  
  1131.     /* scan rest of line for just white space */
  1132.     while (*st) {
  1133.         if ((*st != '\t') && (*st != ' '))
  1134.             return(FALSE);
  1135.         st++;
  1136.     }
  1137.     return(TRUE);
  1138. }
  1139.  
  1140. #if    DEBUGM
  1141. int PASCAL NEAR dispvar(f, n)        /* display a variable's value */
  1142.  
  1143. int f;        /* default flag */
  1144. int n;        /* numeric arg (can overide prompted value) */
  1145.  
  1146. {
  1147.     register int status;    /* status return */
  1148.     VDESC vd;        /* variable num/type */
  1149.     char var[NVSIZE+1];    /* name of variable to fetch */
  1150.  
  1151.     /* first get the variable to display.. */
  1152.     if (clexec == FALSE) {
  1153.         status = mlreply(TEXT55, &var[0], NVSIZE+1);
  1154. /*                 "Variable to display: " */
  1155.         if (status != TRUE)
  1156.             return(status);
  1157.     } else {    /* macro line argument */
  1158.         /* grab token and skip it */
  1159.         execstr = token(execstr, var, NVSIZE + 1);
  1160.     }
  1161.  
  1162.     /* check the legality and find the var */
  1163.     findvar(var, &vd, NVSIZE + 1);
  1164.         
  1165.     /* if its not legal....bitch */
  1166.     if (vd.v_type == -1) {
  1167.         mlwrite(TEXT52, var);
  1168. /*            "%%No such variable as '%s'" */
  1169.         return(FALSE);
  1170.     }
  1171.  
  1172.     /* and display the value */
  1173.     strcpy(outline, var);
  1174.     strcat(outline, " = ");
  1175.  
  1176.     /* and lastly the current value */
  1177.     strcat(outline, fixnull(getval(var)));
  1178.  
  1179.     /* expand '%' to "%%" so mlwrite wont bitch */
  1180.     makelit(outline);
  1181.  
  1182.     /* write out the result */
  1183.     mlforce(outline);
  1184.     update(TRUE);
  1185.  
  1186.     /* and return */
  1187.     return(TRUE);
  1188. }
  1189.  
  1190. /*    describe-variables    Bring up a fake buffer and list the contents
  1191.                 of all the environment variables
  1192. */
  1193.  
  1194. PASCAL NEAR desvars(f, n)
  1195.  
  1196. int f,n;    /* prefix flag and argument */
  1197.  
  1198. {
  1199.     register WINDOW *wp;    /* scanning pointer to windows */
  1200.     register BUFFER *varbuf;/* buffer to put variable list into */
  1201.     register int uindex;    /* index into uvar table */
  1202.     char outseq[256];    /* output buffer for keystroke sequence */
  1203.  
  1204.     /* and get a buffer for it */
  1205.     varbuf = bfind(TEXT56, TRUE, 0);
  1206. /*           "Variable list" */
  1207.     if (varbuf == NULL || bclear(varbuf) == FALSE) {
  1208.         mlwrite(TEXT57);
  1209. /*            "Can not display variable list" */
  1210.         return(FALSE);
  1211.     }
  1212.  
  1213.     /* let us know this is in progress */
  1214.     mlwrite(TEXT58);
  1215. /*        "[Building variable list]" */
  1216.  
  1217.     /* build the environment variable list */
  1218.     for (uindex = 0; uindex < NEVARS; uindex++) {
  1219.  
  1220.         /* add in the environment variable name */
  1221.         strcpy(outseq, "$");
  1222.         strcat(outseq, envars[uindex]);
  1223.         pad(outseq, 14);
  1224.             
  1225.         /* add in the value */
  1226.         strcat(outseq, gtenv(envars[uindex]));
  1227.  
  1228.         /* and add it as a line into the buffer */
  1229.         if (addline(varbuf, outseq) != TRUE)
  1230.             return(FALSE);
  1231.     }
  1232.  
  1233.     if (addline(varbuf, "") != TRUE)
  1234.         return(FALSE);
  1235.  
  1236.     /* build the user variable list */
  1237.     for (uindex = 0; uindex < MAXVARS; uindex++) {
  1238.         if (uv[uindex].u_name[0] == 0)
  1239.             break;
  1240.  
  1241.         /* add in the user variable name */
  1242.         strcpy(outseq, "%");
  1243.         strcat(outseq, uv[uindex].u_name);
  1244.         pad(outseq, 14);
  1245.             
  1246.         /* add in the value */
  1247.         strcat(outseq, uv[uindex].u_value);
  1248.  
  1249.         /* and add it as a line into the buffer */
  1250.         if (addline(varbuf, outseq) != TRUE)
  1251.             return(FALSE);
  1252.     }
  1253.  
  1254.     /* display the list */
  1255.     wpopup(varbuf);
  1256.     mlerase();    /* clear the mode line */
  1257.     return(TRUE);
  1258. }
  1259.  
  1260. /*    describe-functions    Bring up a fake buffer and list the
  1261.                 names of all the functions
  1262. */
  1263.  
  1264. PASCAL NEAR desfunc(f, n)
  1265.  
  1266. int f,n;    /* prefix flag and argument */
  1267.  
  1268. {
  1269.     register WINDOW *wp;    /* scanning pointer to windows */
  1270.     register BUFFER *fncbuf;/* buffer to put function list into */
  1271.     register int uindex;    /* index into funcs table */
  1272.     char outseq[80];    /* output buffer for keystroke sequence */
  1273.  
  1274.     /* get a buffer for the function list */
  1275.     fncbuf = bfind(TEXT211, TRUE, 0);
  1276. /*           "Function list" */
  1277.     if (fncbuf == NULL || bclear(fncbuf) == FALSE) {
  1278.         mlwrite(TEXT212);
  1279. /*            "Can not display function list" */
  1280.         return(FALSE);
  1281.     }
  1282.  
  1283.     /* let us know this is in progress */
  1284.     mlwrite(TEXT213);
  1285. /*        "[Building function list]" */
  1286.  
  1287.     /* build the function list */
  1288.     for (uindex = 0; uindex < NFUNCS; uindex++) {
  1289.  
  1290.         /* add in the environment variable name */
  1291.         strcpy(outseq, "&");
  1292.         strcat(outseq, funcs[uindex].f_name);
  1293.  
  1294.         /* and add it as a line into the buffer */
  1295.         if (addline(fncbuf, outseq) != TRUE)
  1296.             return(FALSE);
  1297.     }
  1298.  
  1299.     if (addline(fncbuf, "") != TRUE)
  1300.         return(FALSE);
  1301.  
  1302.     /* display the list */
  1303.     wpopup(fncbuf);
  1304.     mlerase();    /* clear the mode line */
  1305.     return(TRUE);
  1306. }
  1307.  
  1308. pad(s, len)    /* pad a string to indicated length */
  1309.  
  1310. char *s;    /* string to add spaces to */
  1311. int len;    /* wanted length of string */
  1312.  
  1313. {
  1314.     while (strlen(s) < len) {
  1315.                 strcat(s, "          ");
  1316.         s[len] = 0;
  1317.     }
  1318. }
  1319. #endif
  1320.